import { defineStore } from "pinia";
import { EncryptStorage } from "encrypt-storage";
//需注意使用stateManagementUse
export const encryptStorage = new EncryptStorage("YM1234567890", {
  stateManagementUse: true,
});
export interface UserConfig<T = any> {
  vipClass: T;
  payType: T;
  coinType: T;
}

export const useUserConfig = defineStore("userConfig", {
  state: (): UserConfig => {
    return {
      vipClass: [],
      payType: [],
      coinType: [],
    };
  },
  actions: {
    setVipClass(vipClass: any) {
      this.$state.vipClass = vipClass;
    },
    setPayType(payType: any) {
      this.$state.payType = payType;
    },
    setCoinType(coinType: any) {
      this.$state.coinType = coinType;
    },
  },

  persist: {
    enabled: true,
    key: "userConfig", //如果需要对存储的密钥key进行命名
    storage: encryptStorage,
    // storage: localStorage, //如果不使用加密处理
    paths: ["userConfig"],
  },
});
